package it.csi.finregio.finreges.presentation.streaminfo;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.struts.actions.DownloadAction.StreamInfo;

public abstract class AbstractStreamInfo implements StreamInfo {

	
	private byte[] bytes;
	private boolean throwException = false;
	private String errorMessage;
	private String fileName;

	public AbstractStreamInfo(InputStream in) {
		try {
			this.bytes = IOUtils.toByteArray(in);
		} catch (IOException e) {
			throwException = true;
			errorMessage = e.getMessage();
		}
	}
	
	public InputStream getInputStream() throws IOException {
		return new ByteArrayInputStream(bytes);
	}

	public boolean isThrowException() {
		return throwException;
	}

	public String getErrorMessage() {
		return errorMessage;
	}
	
	public String getFileName(){
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

}
